Imports System
Imports System.Collections.Generic
Imports System.Text
Imports Microsoft.Practices.EnterpriseLibrary.Caching
Imports ViewStateEliminator_VB.ViewStateEliminator.Configuration
Imports Microsoft.Practices.EnterpriseLibrary.Caching.Expirations
Namespace ViewStateEliminator.Data

    Public Class ViewStateApplicationCacheStorage
        Implements ViewStateEliminator.Data.IViewstateStorage
        Private _cache As CacheManager
        Public Sub New()
            _cache = CacheFactory.GetCacheManager("ViewStateApplicationCacheStorage")
        End Sub
        Public Sub Add(ByVal viewstateItem As System.Collections.Generic.KeyValuePair(Of Object, String)) Implements IViewstateStorage.Add
            _cache.Add(viewstateItem.Key.ToString(), viewstateItem.Value)
        End Sub

        Public Function [Get](ByVal key As Object) As System.Collections.Generic.KeyValuePair(Of Object, String) Implements IViewstateStorage.Get
            Return New KeyValuePair(Of Object, String)(key, CType(_cache.GetData(key.ToString()), String))
        End Function

        Public Sub Remove(ByVal key As Object) Implements IViewstateStorage.Remove
            _cache.Remove(key.ToString())
        End Sub
    End Class

End Namespace